package cn.hou.java.designpattern._08flyweight;

import java.util.HashMap;
import java.util.Map;

public class StudentFactory {
	
	//共享数据池
	private Map<String,Student> pool;

	public StudentFactory() {
		this.pool=new HashMap<String,Student>();
	}
	
	//获取数据
	public Student getStudent(String ID){
		Student student=pool.get(ID);//从共享池获取
		if(student==null){//如果获取不到,则新创建一个添加进共享池
			student=new Student(ID);
			pool.put(ID, student);
		}
		return student;
	}

}
